home *** CD-ROM | disk | FTP | other *** search
- /*
- * FILE: app.h
- * AUTHOR: R. Gonzalez
- * CREATED: August 25, 1990
- *
- * Defines generic application class. An application may be derived
- * from any of the derived abstract application classes, such as the
- * Command_App (command-line app.) class. To change the "look" of
- * the application the programmer need only change the parent of the
- * new application to a different abstract application class, such as
- * Menu_App. Also, unless the TC-only 'inherited' keyword is used to
- * call the parent class, explicit calls to the parent class must be
- * changed as well. To make this easier we've defined a macro like:
- *
- * # define PARENT_CLASS Command_App
- *
- * in the header for each of the derived abstract classes (Command_App,
- * Menu_App, etc.). Use PARENT_CLASS to refer to the parent class.
- * Then you can change the look of your application simply by #includ-
- * ing the appropriate header file! An example is discussed below.
- *
- * Limitations: The user interface of the programmer's application
- * must rely upon a set of commands. Other than this, the only way
- * the application may communicate with the user is via character
- * strings passed in query() and respond() messages. No graphics
- * are provided for, in keeping with the lowest-common-denominator
- * user interface.
- *
- **********************************************************************
- *
- * Here's how to write your own application class My_App. Create
- * the header myapp.h and #include the desired parent application
- * class header (comapp.h, menapp.h, or macapp.h). Define your
- * class like:
- *
- * struct My_App:PARENT_CLASS
- * {
- * .
- * .
- * };
- *
- * using any new instance variables you like, and overriding init
- * and destroy to perform your own initializations.
- *
- * Next, create the source file myapp.c. Here you should define
- * static functions for each command your application will handle.
- * Each of these should return a boolean and take a single argument:
- * a pointer to an object of type My_App. This parameter must
- * be used to access your application's instance variables as well
- * as the query() and respond() functions. For example:
- *
- * static boolean open(My_App* app_ptr)
- * {
- * char filename[80];
- *
- * app_ptr->query("Enter file name: ",filename);
- * app_ptr->file = fopen(filename,"r");
- * .
- * .
- * }
- *
- * (See the note below for why static functions are used instead
- * of member functions.) In your init method you should first call
- * PARENT_CLASS::init(), then send log_command messages to the menu
- * instance variable (inherited) to associate a name and function
- * pointer to each command your application handles. The parent
- * class will automatically call the appropriate static function
- * when the corresponding command is selected by the user.
- *
- **********************************************************************
- *
- * NOTE: This version logs the command name and number, as well as
- * a pointer to the function itself, into the menu object. The
- * current implementation of TC (as with early versions of C++) does
- * not support taking the address of a method. Therefore for now
- * we are using static functions to implement this. In the future
- * it would be nice to use member functions instead, so that they
- * may easily access instance variables of the derived application
- * class. (The "app_ptr->..." notation mentioned above will not be
- * needed.)
- *
- * In our earlier version, the programmer did not log a pointer to
- * the command function into the menu; rather, he/she had to write a
- * do_command() method for the new application which contained a case
- * statement selecting the function associated with the command
- * chosen. This approach allowed the command functions to be member
- * functions, but was otherwise more prone to errors.
- */
-
- # ifndef app_h
- # define app_h
-
- # include "class.h"
-
- struct Menu;
-
- /************************************************************************
- * abstract application class
- ************************************************************************/
- struct Generic_App:Generic_Class
- {
- struct Menu *menu;
- boolean done;
-
- boolean init(void);
- virtual void run(void);
- virtual void query(char*,char[]);
- virtual void respond(char*);
- boolean destroy(void);
- };
-
- # include "menu.h"
-
- # endif
-